package com.briup.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.briup.bean.Email;
import com.briup.bean.User;
import com.briup.common.exception.UserException;
import com.briup.service.IUserService;
import com.briup.service.impl.IUserServiceImpl;
import com.briup.util.EmailTool;
import com.briup.util.RandomNumTool;




@WebServlet("/For1UserSer")
public class For1UserSer extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
	@SuppressWarnings("static-access")
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		String email=request.getParameter("email");
		
		HttpSession session=request.getSession();
		String username=(String) session.getAttribute("username");
		IUserService service=new IUserServiceImpl();
		try {
			User u=service.getUserByName(username);
			String ema=u.getEmail();
			String msg;
			if(!email.equals(ema)) {
                 msg="输入的邮箱不正确";
			}else {
				msg="输入的邮箱正确";
				session.setAttribute("email", email);
			}
			PrintWriter pw=response.getWriter();
			pw.write(msg);
			pw.flush();
			pw.close();
		} catch (UserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
